﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using System.Linq;

namespace LegtionMVVM
{
    [Serializable]
    public class NotifyPropertyChanged : INotifyPropertyChanged,IDisposable
    {
        #region Proerty       
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        internal Hashtable otherBindingSource = new Hashtable();
        #endregion
        public virtual void RaisePropertyChanged(string prop)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(prop));
            }
        }
        internal void RaisePropertyChanged(params string[] propertyNames)
        {
            if (propertyNames != null && PropertyChanged != null)
            {    
                foreach (string prop in propertyNames)
                {
                    RaisePropertyChanged(prop);
                }
            }
            
        }
        #endregion
        #region CollectionChanged
        internal void OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
            }
            //System.Windows.Forms.MessageBox.Show("Use CollectionChanged EventHandler");
        }
        #endregion
        #region Other

        public NotifyPropertyChanged() { }
 
         public void ViewDisposed(object sender, EventArgs e)
         {
             Dispose(false);
         }
        #endregion

         public void Dispose( )
         {
             Dispose(true);
         }
         private void Dispose(bool closeView=true)
         {
             Document.CloseDocument<Form, NotifyPropertyChanged>(this,closeView);
             System.GC.Collect();
         }
    }
    enum DisposeState
    {
        WaitDisposing=0,
        Disposing=10,
        Disposed=20
    }

 

}
